//该中间的目的为配合实操改版，将pc端跳转实操商品的路由重定向到实操课程页面，移动端跳转实操商品落地页
function userAgent(ua) {
  var isWindowsPhone = /(?:Windows Phone)/.test(ua),
    isSymbian = /(?:SymbianOS)/.test(ua) || isWindowsPhone,
    isAndroid = /(?:Android)/.test(ua),
    isFireFox = /(?:Firefox)/.test(ua),
    isChrome = /(?:Chrome|CriOS)/.test(ua),
    isTablet =
      /(?:iPad|PlayBook)/.test(ua) ||
      (isAndroid && !/(?:Mobile)/.test(ua)) ||
      (isFireFox && /(?:Tablet)/.test(ua)), //判断平板
    isPhone = /(?:iPhone)/.test(ua) && !isTablet,
    isPc = !isPhone && !isAndroid && !isSymbian && !isTablet
  return {
    isTablet: isTablet,
    isPhone: isPhone,
    isAndroid: isAndroid,
    isPc: isPc
  }
}

module.exports = async (req, res, next) => {
  let ua = req.headers['user-agent']
  let url = req.url
  let isSpecialRedirect = url.includes('2020003000349') || url.includes('2020001000019123')
  let isPC = userAgent(ua).isPc
  if (isSpecialRedirect) {
    res.redirect(301,isPC?'/courses/4.html':'/public/wxpub/page/sc_page/member_product.html')
    return
  }
  await next()
}
